/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package poker.greentable;

import java.util.ArrayList;
import java.util.HashMap;
import poker.cards.Card;
import poker.cards.CardsConstants;

/**
 * Klasa obslugujaca graczy oraz krupiera, odpowiadajaca za wszystkie akcje w pokerze
 * @author Norteromius
 */
public class Table {
    private ArrayList<Card> deck = new ArrayList<Card>();
    private ArrayList<Card> newDeck = new ArrayList<Card>();
    private ArrayList<Player> players = new ArrayList<Player>();
    private Croupier croupier = new Croupier();
    private HashMap cardKindsMap = new HashMap();
    private HashMap cardColorsMap = new HashMap();
    
    public Table(){
        createKinds();
        createColors();
        createDeck();
    }
    
    public void addPlayer(Player player){
        players.add(player);
    }
    
    public ArrayList<Card> getNewDeck()
    {
        return newDeck;
    }
    
    public int getPlayersNum()
    {
        return players.size();
    }
    /**
     * tworzenie nowej talii
     */
    private void createDeck(){
        for (int j = 0; j < 4; j++){
            for (int i = 0; i < CardsConstants.KEY_SETTINGS_COUNT_TYPE; i++){
                Card newCard = new Card(j, i+2);
                deck.add(newCard);
            }
        }
        /*for (int i = 0; i < 52; i++)
        {   
            deck.add(new Card(i));  
        }*/
    }
    
    
    /**
     * 
     */
    public void startGame(){
        newDeck = this.croupier.mixDeck(deck);
        
        this.players = this.croupier.dealRandomCards(players, newDeck);
        
    }
    
    /**
     * tworzenie zestawu mozliwych typow kart
     * HashMap - by mozna bylo sie odwolac dynamicznie podczas zapelniania talii
     */
    private void createKinds(){
        cardKindsMap.put("2", CardsConstants.KEY_TYPE_2);
        cardKindsMap.put("3", CardsConstants.KEY_TYPE_3);
        cardKindsMap.put("4", CardsConstants.KEY_TYPE_4);
        cardKindsMap.put("5", CardsConstants.KEY_TYPE_5);
        cardKindsMap.put("6", CardsConstants.KEY_TYPE_6);
        cardKindsMap.put("7", CardsConstants.KEY_TYPE_7);
        cardKindsMap.put("8", CardsConstants.KEY_TYPE_8);
        cardKindsMap.put("9", CardsConstants.KEY_TYPE_9);
        cardKindsMap.put("10", CardsConstants.KEY_TYPE_10);
        cardKindsMap.put("11", CardsConstants.KEY_TYPE_11);
        cardKindsMap.put("12", CardsConstants.KEY_TYPE_12);
        cardKindsMap.put("13", CardsConstants.KEY_TYPE_13);
        cardKindsMap.put("14", CardsConstants.KEY_TYPE_14);
     
    }
    
    /*
     * tworzenie mozliwych kolorow kart
     */
    private void createColors(){
        cardColorsMap.put("0", CardsConstants.KEY_COLOR_CLUB);
        cardColorsMap.put("1", CardsConstants.KEY_COLOR_DIAMOND);
        cardColorsMap.put("2", CardsConstants.KEY_COLOR_HEART);
        cardColorsMap.put("3", CardsConstants.KEY_COLOR_SPADE);
    }
    
    
}
